Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Sametime Forum

HCL Sametime Forum


  

PreviousPrevious NextNext

RE: How do I write a java agent in domino that sends an announcement?
~Elizabeth Xanjumilyakoi 7.Jul.04 04:48 PM a Web browser
Applications development All Releases Windows NT/2000


Thank you for that pointer! I got the example to work in eclipse and in domino. Pasted here for anyone who doesn't want to spend a few days getting the bugs worked out. This program can also be easily adapted to run in a domino agent. It requires the STComm.jar file. Oh and I'm not Heather Smith from UK, I'm from the Watson site.
Best regards,
Heather Smith

import com.lotus.sametime.announcement.*;
import com.lotus.sametime.awareness.*;
import com.lotus.sametime.community.*;
import com.lotus.sametime.core.comparch.*;
import com.lotus.sametime.core.constants.*;
import com.lotus.sametime.core.types.*;
import com.lotus.sametime.lookup.*;

public class UserStatus implements LoginListener , StatusListener, ResolveListener{

private STSession m_session;
private CommunityService m_communityService;
private LookupService m_lookupService;
private AnnouncementService m_announcementService;
private AwarenessService m_awarenessService;
private Resolver m_resolver;
private WatchList m_watchList;
private STUser m_requestedUser;

private String m_strUserName;
private String m_strAnnouncement;
private short m_shUserStatus;
private short m_shAnnouncementStatus;
private boolean m_bSetup;
private boolean m_bResolved;
private boolean m_bFinished;

public void loggedOut(LoginEvent loginEvent){

}
/* (non-Javadoc)
* @see com.lotus.sametime.lookup.ResolveListener#resolveConflict(com.lotus.sametime.lookup.ResolveEvent)
*/
public void resolveConflict(ResolveEvent arg0) {
// TODO Auto-generated method stub

}
/* (non-Javadoc)
* @see com.lotus.sametime.lookup.ResolveListener#resolveFailed(com.lotus.sametime.lookup.ResolveEvent)
*/
public void resolveFailed(ResolveEvent arg0) {
// TODO Auto-generated method stub

}
public void groupCleared(StatusEvent statusEvent){

}

public short getUserStatus(String userToFind)
{
m_strUserName = userToFind;
m_bSetup = false;
try
{
m_session = new STSession("UserStatus"+this);
}
catch(DuplicateObjectException doe)
{
doe.printStackTrace();
return -1;
}

m_session.loadSemanticComponents();
m_session.start();
m_communityService = (CommunityService) m_session.getCompApi(CommunityService.COMP_NAME);
m_lookupService = (LookupService) m_session.getCompApi(LookupService.COMP_NAME);
login();
int setupAttempts = 0;
do
{
if(++setupAttempts > 5000)
{
System.err.println("Setup attempt timed out");
m_bSetup=true;
}
try
{
Thread.sleep(5);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
while (m_bSetup== false);
if(isLoggedIn() == false)
{
System.err.println("Error: cannot login to Sametime server");
return -1;
}
resolve();
return m_shUserStatus;


}

private boolean isLoggedIn()
{
// System.out.println("m_communityService"+m_communityService);
if(m_communityService == null)
{
return false;
}
return m_communityService.isLoggedIn();
}

private void login()
{
m_communityService.addLoginListener(this);
m_communityService.loginByPassword("<servername>", "<userid>", "<password>");
int loginAttempts = 0;
boolean loginExpired = false;
do
{
if(++loginAttempts > 1000)
{
loginExpired = true;
}
try
{
Thread.sleep(5);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
while ( isLoggedIn()==false && loginExpired == false);
System.out.println("login expired"+loginExpired);
if(isLoggedIn() == false)
{
m_session.stop();
m_session.unloadSession();
m_bSetup= true;
}
}
public void loggedIn(LoginEvent event)
{
System.out.println("loggedIn()");
m_resolver = m_lookupService.createResolver(false, false, true, false);
System.out.println("Awareness Service:"+AwarenessService.COMP_NAME);
m_awarenessService = (AwarenessService)m_session.getCompApi(AwarenessService.COMP_NAME);
m_watchList = m_awarenessService.createWatchList();
m_watchList.addStatusListener(this);
m_announcementService = (AnnouncementService) m_session.getCompApi(AnnouncementService.COMP_NAME);
m_bSetup = true;
}
private void resolve()
{
m_bResolved = false;
m_resolver.addResolveListener(this);
m_resolver.resolve(m_strUserName);
int resolveAttempts = 0;
do
{
if(++resolveAttempts > 1000)
{
m_bResolved=true;
}
try
{
Thread.sleep(5);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
while (m_bResolved == false);
m_resolver.removeResolveListener(this);
m_bFinished=false;
int finishAttempts=0;
do
{
if(++finishAttempts>1000)
{
m_bFinished=true;
}
try
{
Thread.sleep(5);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
while (m_bFinished == false);
m_watchList.removeStatusListener(this);
m_watchList.close();
m_communityService.logout();
boolean logoutExpired = false;
int logoutAttempts = 0;
do{
if(++logoutAttempts > 1000)
{
logoutExpired = true;
}
try
{
Thread.sleep(5);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
while(isLoggedIn()== true && logoutExpired == false);
m_session.stop();
m_session.unloadSession();
}
public void resolved(ResolveEvent event)
{
System.out.println("resolved()");
if(event.getName().compareTo(m_strUserName)==0)
{
m_requestedUser = (STUser) event.getResolved();
m_watchList.addItem(m_requestedUser);
m_bResolved = true;
}
}
public void userStatusChanged(StatusEvent event)
{
System.out.println("userStatusChanged()");
STWatchedUser[] watchedUser = event.getWatchedUsers();
m_shUserStatus = watchedUser[0].getStatus().getStatusType();
if(m_shUserStatus ==32)
{
STObject stObject[] = {m_requestedUser};
System.out.println("sendAnnouncement");
m_strAnnouncement="The Goddess of Sametime requests that you get off her network! :-)";
m_announcementService.sendAnnouncement(stObject, false, m_strAnnouncement);
m_shAnnouncementStatus = 0;
m_bFinished = true;
}
else
{
m_shAnnouncementStatus = -1;
m_bFinished = true;
}
}





public static void main (String[] args)
{
if (args.length != 1)
{
System.out.println("Usage: UserStatus userToFind");
}
short shUserStatus = new UserStatus().getUserStatus(args[0]);
System.out.println("Status for user " + args[0] + ": " + shUserStatus);
}
}




How do I write a java agent in domi... (~Elizabeth Xanj... 6.Jul.04)
. . RE: How do I write a java agent in ... (~Mark Bubnitexa... 6.Jul.04)
. . . . RE: How do I write a java agent in ... (~Elizabeth Xanj... 7.Jul.04)
. . . . . . RE: How do I write a java agent in ... (~John Opfreevit... 20.Jul.05)


Document Options






  Document options
Print this pagePrint this page

Search this forum

Forum views and search


  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Category
Platform
Release
Advanced search

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS